import { CallHandler, ExecutionContext, Injectable, NestInterceptor } from "@nestjs/common";
import { map, Observable } from "rxjs";

interface data<T>{
    data:T
}
// 响应拦截器

@Injectable()
export class ResponseInterceptor<T = any> implements NestInterceptor {
    intercept(context: ExecutionContext, next: CallHandler<any>): Observable<data<T>> | Promise<Observable<data<T>>> {
        return next.handle().pipe(map(data => {
            return {
                data,
                status: 0,
                success: true,
                message: "成功"

            }
        }))
    }
    
}